import unittest
import requests

from api.api_dlce import RegLoginApi
from api.api_tz import TenderApi
from common.html解析 import html_util
from common.封装数据库操作方法 import init_tender_info
from common.断言参数化 import common_assert


class TestTender(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 借款标测试数据初始化
        init_tender_info()

    def setUp(self):
        # 创建session对象
        self.session=requests.session()
        # 调用投资模块类
        self.tz=TenderApi(self.session)
        # 调用登录模块类
        self.dl=RegLoginApi(self.session)


    def tearDown(self):
        # 关闭session对象
        self.session.close()


    # 投资测试用例
    def test01_tender(self):
        #用户登录
        self.dl.user_login('15666666111', '123456')
        #投资
        response=self.tz.tender(642,1000)
        common_assert(self, response, 200, 200, 'form')




    # 第三方投资测试用例
    def test02_third_tender(self):
        self.dl.user_login('15666666111', '123456')
        resp=self.tz.tender('642',1000)

        url=html_util(resp)[0]
        form_dict = html_util(resp)[1]
        response = self.tz.third_tender(url, form_dict)
        data=response.text
        print(data)
        self.assertIn('OK', response.text)

